package com.distributer.message.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.distributer.message.mapper.MessageMapper;
import com.distributer.message.model.Message;
import com.distributer.message.producer.MessageRequestHander;
import com.distributer.message.service.MessageService;

@Service
public class MessageServiceImpl implements MessageService{

	@Autowired
	private MessageMapper messageMapper;
	@Autowired
	private KafkaTemplate<String, String> kafkaTemplate;
	@Autowired
	private MessageRequestHander messageRequestHander;
	
	@Override
	@Transactional(rollbackFor={Exception.class})
	public String reserveSendMessage(Message message) {
		messageMapper.insert(message);
		return message.getMessageSquece();
	}

	@Override
	@Transactional(rollbackFor={Exception.class})
	public void confirmSendMessage(String messageSquece) {
		Message message = messageMapper.queryMessageByMessagesquce(messageSquece);
		//调用kafka发送消息
		messageRequestHander.messageRequestHander(message, kafkaTemplate);
	}

	@Override
	@Transactional(rollbackFor={Exception.class})
	public void sendMessage(Message message) {
		messageMapper.insert(message);
		//调用kafka发送消息
		messageRequestHander.messageRequestHander(message, kafkaTemplate);
	}

	@Override
	public void confirmMessage(Message message) {
		
	}

	@Override
	public void ackConfirmMessage(Message message) {
		
	}

	@Override
	public void retryMessage(Message message) {
		
	}

	@Override
	public List<Message> queryWaitConfirmMessage(Date conditionTime) {
		
		return null;
	}

	@Override
	public List<Message> queryWaitSendMessage(Date conditionTime) {
		
		return null;
	}

	@Override
	public Message queryMessageByMessageSquece(String messageSquece) {
		return messageMapper.queryMessageByMessagesquce(messageSquece);
	}

	@Override
	public Message queryMessageByMessageNo(String messageNo) {
		
		return null;
	}

	@Override
	public void updateStatusToWaitConfirm() {

	}

	@Override
	public void updateMessageToDead() {
		
	}

	@Override
	public void updateMessageToDead(Message message) {
		
	}

	@Override
	public int updateWaitSendMessageStatusToSending(Date conditionTime) {
		
		return 0;
	}

	@Override
	public int updateWaitConfirmMessageStatusToConfriming(Date conditionTime) {
		
		return 0;
	}

	@Override
	public void messageStatusToWaitConfirmFromConfirmingUpdate() {
		
	}

	@Override
	public void messageStatusToWaitSendFromSendingUpdate() {
		
	}

}
